/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import model.GroupAccount;

/**
 *
 * @author adriano.lourenco
 */
public class PlanAccountDAO implements DAO {

    private final DataSource dataSource;

    public PlanAccountDAO() {
        dataSource = new DataSource();
    }

    public void create(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public void delete(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public void update(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public Object read(Object o) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    public Object findAll() {
        try {
            String sql = "SELECT * FROM groupaccount";

            PreparedStatement ps = dataSource.getConnection().prepareStatement(sql);
            ArrayList<GroupAccount> listaGrupoContas = new ArrayList<GroupAccount>();
            ResultSet rs = ps.executeQuery();
            while (rs.next()) {

                GroupAccount ga = new GroupAccount();

                ga.setIdgroupaccount(rs.getString("GroupAccount.idgroupaccount"));
                ga.setLstGrupoDeContas(rs.getString("GroupAccount.descricao"));

                listaGrupoContas.add(ga);
             
                
            }
            return listaGrupoContas;

        } catch (Exception e) {
            System.err.println("GROUPACCOUNT.READ - " + e.getMessage());
            return null;
        }
        
        
    }

    public void closeDAO() {
        dataSource.closeConnection();
    }

}
